package Well_Game;

import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import java.util.ArrayList;

class Cell extends Pane {
    private  int[][] well;
    ArrayList<Rectangle> list = new ArrayList<>();
    Cell(){
        well = new int[3][3];
        initialize();
        int width = 100;
        int height = 100;
        list.add(new Rectangle(0,0,width,height));
        list.add(new Rectangle(100,0,width,height));
        list.add(new Rectangle(200,0,width,height));
        list.add(new Rectangle(0,100,width,height));
        list.add(new Rectangle(100,100,width,height));
        list.add(new Rectangle(200,100,width,height));
        list.add(new Rectangle(0,200,width,height));
        list.add(new Rectangle(100,200,width,height));
        list.add(new Rectangle(200,200,width,height));

        for(int i = 0; i < 9; i++){
            list.get(i).setStroke(Color.BLACK);
            list.get(i).setFill(Color.LIGHTGRAY);
        }
        reloadrectangle();
    }
    void printO(int i){
        Circle circle = new Circle(40);
        circle.setFill(Color.LIGHTGRAY);
        circle.setStroke(Color.BLACK);
        circle.setCenterX(i % 3 *100 + 50);
        circle.setCenterY(i / 3 * 100 + 50);
        getChildren().add(circle);
    }
    void printX(int i){
        int x = (i % 3) * 100 + 50;
        int y = (i / 3) * 100 + 50;
        Line line1 = new Line(x-40, y-40, x+40, y+40);
        Line line2 = new Line(x+40,y-40,x-40,y+40);
        line1.setStroke(Color.BLACK);
        line2.setStroke(Color.BLACK);
        getChildren().addAll(line1,line2);
    }
    void random_well_game(){
        for (int i = 0; i < 9; i++) {
            int num = (int)(Math.random() * 3);
            switch (num){
                case 1 :{
                    printX(i);
                    break;
                }
                case 2 :{
                    printO(i);
                    break;
                }
                default:break;
            }
        }
    }
    int getWell(int i, int j) {
        return well[i][j];
    }
    void setWell(int i, int j, int num) {
        well[i][j] = num;
    }
    void initialize() {
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                setWell(i,j,0);
    }
    void reloadrectangle(){
        for (Rectangle aList : list) {
            getChildren().add(aList);
        }
    }
}
